package cn.lanqiao.springboot.mapper;

import cn.lanqiao.springboot.entity.User;
import cn.lanqiao.springboot.vo.QueryUserVO;
import cn.lanqiao.springboot.vo.UserVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {

    @Select("select su.user_id, su.user_name, sr.role_id, sr.role_name, su.password " +
            "from system_user su, system_user_role sur, system_role sr \n" +
            "where su.user_id = sur.user_id and sr.role_id = sur.role_id and su.user_name = #{userName}")
    UserVO checkUser(User user);

    @Insert("insert into system_user (user_name,password,email) values (#{userName},#{password},#{email})")
    @Options(useGeneratedKeys = true,keyProperty = "userId")
    void insert(UserVO userVO);

    @Delete("delete from system_user where user_id = #{userId}")
    void delete(int userId);

    @Update("update system_user set user_name = #{userName}, password = #{password}, email = #{email} where user_id = #{userId}")
    void update(UserVO userVO);

    List<UserVO> getUserList(QueryUserVO queryUserVO);

    @Select("select su.user_id, su.user_name, sr.role_id, sr.role_name, su.password " +
            "from system_user su, system_user_role sur, system_role sr \n" +
            "where su.user_id = sur.user_id and sr.role_id = sur.role_id and su.phone = #{phone}")
    UserVO getUserByPhone(String phone);
}
